package com.dongdong.controller;

import com.dongdong.aop.AnLog;
import com.dongdong.em.Result;
import com.dongdong.page.PageParams;
import com.dongdong.service.SpecService;
import com.dongdong.vo.BrandVO;
import com.dongdong.vo.SpecVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("spec")
public class SpecController {

    @Autowired
    private SpecService specService;

    @PostMapping("getSpecList")
    @AnLog //切面编程日志   利用注解的方式到controller单独使用     不需要编写路径
    public Result getSpecList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        PageParams<SpecVO> voList = specService.getSpecList(pageNum, pageSize);
        return Result.OK().setData(voList);
    }

    //模糊查询
    @PostMapping("findSpecList")
    public Result findSpecList(@RequestBody SpecVO specVO) {
        List<SpecVO> specList = specService.findSpecList(specVO);
        return Result.OK().setData(specList);
    }

    //回显
    @GetMapping("getSpecById")
    public Result getSpecById(@RequestParam Long id) {
        SpecVO vo = specService.getSpecById(id);
        return Result.OK().setData(vo);
    }

    //修改
    @PutMapping("updateSecp")
    public Result updateSecp(@RequestBody SpecVO specVO) {
        int i = specService.updateSecp(specVO);
        if (i < 0) {
            return Result.ERROR();
        }
        return Result.OK();
    }

    //增加
    @PostMapping("InsertSpec")
    public Result InsertSpec(@RequestBody SpecVO specVO) {
        int i = specService.insertSpec(specVO);
        if (i < 0) {
            return Result.ERROR();
        }
        return Result.OK();
    }

    //删除
    @DeleteMapping("deleteSpec/{arr}")
    public Result deleteSpec(@PathVariable Long[] arr){
        int i = specService.deleteSpec(arr);
        if (i < 0) {
            return Result.ERROR();
        }
        return Result.OK();
    }


    //获取select2
    @PostMapping("getSpecListAndSelect2")
    public Result getSpecListAndSelect2(){
        List<SpecVO> speclist=specService.getSpecListAndSelect2();
        return Result.OK().setData(speclist);
    }

    //获取所有规格选项

}
